/*
Different Ways to Add Parentheses Total Accepted: 965 Total Submissions: 3568 My Submissions Question Solution
Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +, - and *.


Example 1
Input: "2-1-1".

((2-1)-1) = 0
(2-(1-1)) = 2
Output: [0, 2]


Example 2
Input: "2*3-4*5"

(2*(3-(4*5))) = -34
((2*3)-(4*5)) = -14
((2*(3-4))*5) = -10
(2*((3-4)*5)) = -10
(((2*3)-4)*5) = 10
Output: [-34, -14, -10, -10, 10]

Credits:
Special thanks to @mithmatt for adding this problem and creating all test cases.
*/

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <fstream>
#include <sstream>
#include <unordered_set>
#include <unordered_map>
#include "print.h"
using namespace std;

/**
* Definition for binary tree*/


void testForStack()
{
	stack<int> mystack;
	mystack.push(10);
	mystack.push(20);
	mystack.top() -= 5;
	cout << "mystack.top() is now " << mystack.top() << endl;
}

void testForIntToString()
{
	int a = 10;
	stringstream ss;
	ss << a;
	string str = ss.str();
	cout << str << endl;

	string str1 = to_string(a);

}


/**
* Definition for a binary tree node.
* struct TreeNode {
*     int val;
*     TreeNode *left;
*     TreeNode *right;
*     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
	vector<int> diffWaysToCompute(string input) {
		vector<int> res;

		for (int  i = 0; i < input.size(); i++)
		{
			if (input[i] == '+' || input[i] == '-' || input[i] == '*')
			{
				vector<int> left = diffWaysToCompute(input.substr(0,i));
				vector<int> right = diffWaysToCompute(input.substr(i+1));

				for (int j = 0; j < left.size(); j++)
				{
					for (int k = 0; k < right.size(); k++)
					{
						if (input[i] == '+')
							res.push_back(left[j] + right[k]);
						else if (input[i] == '-')
							res.push_back(left[j] - right[k]);
						else
							res.push_back(left[j] * right[k]);


					}
				}
			}
			

		}

		if (res.empty())
		{
			res.push_back(atoi(input.c_str()));
		}

		return res;
	}
};




/**
* Your BSTIterator will be called like this:
* BSTIterator i = BSTIterator(root);
* while (i.hasNext()) cout << i.next();
*/

int main(int argc, char* argv[])
{

	int a1[] = { 1, 4, 7, 11, 15 };
	int a2[] = { 2, 5, 8, 12, 19 };
	int a3[] = { 3, 6, 9, 16, 22 };
	int a4[] = { 10, 13, 14, 17, 24 };
	int a5[] = { 18, 21, 23, 26, 30 };

	vector<int> level1(a1, a1 + sizeof(a1) / sizeof(int));
	vector<int> level2(a2, a2 + sizeof(a2) / sizeof(int));
	vector<int> level3(a3, a3 + sizeof(a3) / sizeof(int));
	vector<int> level4(a4, a4 + sizeof(a4) / sizeof(int));
	vector<int> level5(a5, a5 + sizeof(a5) / sizeof(int));


	vector<vector<int> > martix;
	martix.push_back(level1);
	martix.push_back(level2);
	martix.push_back(level3);
	martix.push_back(level4);
	martix.push_back(level5);

	string input = "1+2*3";

	Solution s;

	vector<int> result;
	result = s.diffWaysToCompute(input);



	//res = s.productExceptSelf(nums);
	//int n = 7;
	//ifs1.countPrimes(val);

	//strRes = s.findRepeatedDnaSequences(s1);
	//cout << "The result is : " << result << endl;
	//result = s.partition(str);
	//stackTree.push(p->left);
	//stackTree.push(p->right);
	//if (s1.containsNearbyAlmostDuplicate(vecInt, 1, 2))
	//	cout << " True" << endl;
	//else
	//cout << "false" << endl;
	system("pause");
	return 0;
}
//std::unordered_set<std::string> myset =
//{ "hot", "dot", "dog", "lot", "log" };

//std::cout << "myset contains:";
// for (auto it = myset.begin(); it != myset.end(); ++it)
//std::cout << " " << *it;
//;; std::cout << std::endl;

//TreeNode *root = new TreeNode(1);
//TreeNode *left = new TreeNode(2);
//TreeNode *right = new TreeNode(3);

//root->left = left;
//root->right = right;s
/*
//string s1 = "GAGAGAGAGAGA";
string s1 = "GAGAGAGAGAGA";
vector<string> strRes;

TreeNode *root = new TreeNode(1);
TreeNode *left1 = new TreeNode(2);
TreeNode *left2 = new TreeNode(5);

TreeNode *right1 = new TreeNode(3);
TreeNode *right2 = new TreeNode(4);

root->left = left1;
left1->right = left2;

root->right = right1;
right1->right = right2;

//vector<char> level1({ '1', '1', '1', '1', '0' });
//vector<char> level2({ '1', '1', '0', '1', '0' });
//vector<char> level3({ '1', '1', '0', '0', '0' });
//vector<char> level4({ '0', '0', '0', '0', '0' });


vector<vector<char>> grid;
grid.push_back(level1);
grid.push_back(level2);
grid.push_back(level3);
grid.push_back(level4);ss
ListNode *head = new ListNode(1);
ListNode *head1 = new ListNode(2);
ListNode *head2 = new ListNode(6);
ListNode *head3 = new ListNode(3);
ListNode *head4 = new ListNode(4);
ListNode *head5 = new ListNode(5);

ListNode *head6 = new ListNode(6);

head->next = head1;
head1->next = head2;
head2->next = head3;
head3->next = head4;
head4->next = head5;
head5->next = head6;
int val = 6;
char a1[] = { '1', '0', '1', '0', '0' };
char a2[] = { '1', '0', '1', '1', '0' };
char a3[] = { '1', '1', '1', '1', '1' };
char a4[] = { '1', '0', '0', '1', '0' };

vector<char> level1(a1, a1 + sizeof(a1) / sizeof(char));
vector<char> level2(a1, a1 + sizeof(a1) / sizeof(char));
vector<char> level3(a1, a1 + sizeof(a1) / sizeof(char));
vector<char> level4(a1, a1 + sizeof(a1) / sizeof(char));

vector<vector<char> > martix;
martix.push_back(level1);
martix.push_back(level2);
martix.push_back(level3);
martix.push_back(level4);

Solution s;
int result;
result = s.maximalSquare(martix);
*/
